//
//  LGUploadFilesCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/12/30.
//

#import "LGUploadFilesCell.h"

#define itemW  (Screen_W-viewPix(62))/3.0

@interface LGUploadFilesCell()
/**  文件夹名称 */
@property (nonatomic , strong)UILabel *titleLabel;
/**  上传时间 */
@property (nonatomic , strong)UILabel *timeLabel;
/**  报告总数 */
@property (nonatomic , strong)UILabel *totalLabel;
/**  解压状态 */
@property (nonatomic , strong)UILabel *statusLabel;
/**  识别结果 */
@property (nonatomic , strong)UILabel *identifiedLabel;
/**   */
@property (nonatomic , strong)UIButton *deleteBtn;
/**  解压说明 */
@property (nonatomic , strong)UILabel *descLabel;
/**   */
@property (nonatomic , strong)NSDictionary *statusDic;
/**   */
@property (nonatomic , strong)NSDictionary *identifiedDic;

@end

@implementation LGUploadFilesCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.type = LGPositionTypeSingle;
        self.backgroundColor = [UIColor clearColor];
        self.statusDic = @{@"0":@"待解压",@"1":@"已解压",@"2":@"解压上传失败"};
        self.identifiedDic = @{@"0":@"识别队列中",@"1":@"识别完成",@"2":@"需介入"};
        [self createSubView];
    }
    return  self;
}
 
-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    NSString *status = LGNSString(dataDic[@"is_unziped"]);
    NSString *identified = LGNSString(dataDic[@"is_success"]);
    self.titleLabel.text = LGNSString(dataDic[@"filename"]);
    self.timeLabel.text = [NSString stringWithFormat:@"上传时间：%@",dataDic[@"create_time"]];
    self.totalLabel.text = [NSString stringWithFormat:@"报告总数：%@",dataDic[@"report_count"]];
    self.statusLabel.text = [NSString stringWithFormat:@"解压状态：%@",self.statusDic[status]];
    self.identifiedLabel.text = [NSString stringWithFormat:@"识别结果：%@",self.identifiedDic[identified]];
    NSString *unziped = LGNSString(dataDic[@"is_unziped"]);
    self.totalLabel.hidden = [unziped isEqualToString:@"1"]?NO:YES;
    self.statusLabel.hidden = [unziped isEqualToString:@"1"]?NO:YES;
    self.identifiedLabel.hidden = [unziped isEqualToString:@"1"]?NO:YES;
    NSString *desc = [unziped isEqualToString:@"0"]?@"报告解压处理中，刷新后可查看最新结果":[NSString stringWithFormat:@"报告解压上传失败，原因：%@",dataDic[@"error_message"]];
    self.descLabel.text = [unziped isEqualToString:@"1"]?@"":desc;
    CGFloat descTop = [unziped isEqualToString:@"1"]?viewPix(50):viewPix(10);
    [self.descLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(descTop);
    }];
    
}

-(void)deleteReportAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(deleteFileAction:)]) {
        [self.delegate deleteFileAction:LGNSString(self.dataDic[@"medical_report_id"])];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    [self.baseView addSubview:self.titleLabel];

    self.timeLabel = [UILabel lableWithText:@"上传时间：" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    [self.baseView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(5));
        make.left.right.equalTo(self.titleLabel);
    }];
    
    self.totalLabel = [UILabel lableWithText:@"报告总数：" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    self.totalLabel.frame = CGRectMake(viewPix(15), kMaxY(self.timeLabel.frame)+viewPix(5), itemW, viewPix(20));
    [self.baseView addSubview:self.totalLabel];
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.titleLabel);
    }];
    
    self.statusLabel = [UILabel lableWithText:@"解压状态：" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    [self.baseView addSubview:self.statusLabel];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(180));
        make.centerY.equalTo(self.totalLabel);
    }];
    
    self.identifiedLabel = [UILabel lableWithText:@"识别结果：" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    [self.baseView addSubview:self.identifiedLabel];
    [self.identifiedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.totalLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.totalLabel);
    }];
    
    self.descLabel = [UILabel lableWithText:@"" colorString:@"#444444" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    [self.baseView addSubview:self.descLabel];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.baseView).offset(viewPix(15));
        make.right.equalTo(self.baseView).offset(-viewPix(15));
        make.bottom.equalTo(self.baseView).offset(-viewPix(15));
    }];
    
    self.deleteBtn = [UIButton buttonWithTitle:@"删除" titleFont:LGFont(14) normalColor:@"#DD3030" selectColor:@"#DD3030"];
    [self.deleteBtn addBorder:@"#DD3030" lineWidth:1 cornerRidus:5];
    [self.deleteBtn addTarget:self action:@selector(deleteReportAction) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:self.deleteBtn];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(15));
        make.right.equalTo(self.baseView).offset(-viewPix(15));
        make.width.equalTo(@(viewPix(64)));
        make.height.equalTo(@(viewPix(26)));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(15));
        make.left.equalTo(self.baseView).offset(viewPix(15));
        make.right.equalTo(self.deleteBtn.mas_left).offset(-viewPix(10));
    }];
    
}
@end
